﻿using LivestreamE_Commerce.Dto.AllDto;
using LivestreamE_Commerce.Dto.CreateUpdateDto;
using LivestreamE_Commerce.Dto.RBACDto;
using LivestreamE_Commerce.EntityFrameworkCore;
using LivestreamE_Commerce.Enum;
using LivestreamE_Commerce.IRepository;
using LivestreamE_Commerce.IService;
using LivestreamE_Commerce.IService.Ids4;
using LivestreamE_Commerce.IService.RBACIService;
using LivestreamE_Commerce.Model.RBAC;
using LivestreamE_Commerce.Service.Ids4;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace LivestreamE_Commerce.Service.RBACService
{
    public class MyUserService : CrudAppService<UserModel, UserDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateUserDto>, IMyUserService
    {
        private IConfiguration configuration;
        LivestreamE_CommerceDbContext db;
        public MyUserService(IRepository<UserModel, Guid> repository, LivestreamE_CommerceDbContext _db, IConfiguration _configuration) : base(repository)
        {
            db = _db;
            configuration = _configuration;
        }

        public async Task<LiveShopResData<string>> GetLogin(string userName, string userPwd)
        {
            Idis4Service ids4Service = new Idis4Service(configuration);
            string token = await ids4Service.GetIdsTokeAsync(userName, userPwd);
            return new LiveShopResData<string>() { Status = ShopStatus.Succeed, Msg = "获取token成功", Info = token };
        }
        [HttpGet]
        public IEnumerable<UserRoleAllDto> UserPermissionDisplay()
        {
            var list = (from a in db.UserModel
                        join b in db.UserRoleFinder
                        on a.Id equals b.UserId
                        join c in db.RoleModel
                        on b.RoleId equals c.Id
                        join d in db.RoleMenuModel
                        on c.Id equals d.RoleId
                        join e in db.MenuModel
                        on d.MenuId equals e.Id
                        select new UserRoleAllDto
                        {
                            UserName = a.UserName,
                            RoleName = c.RoleName,
                        }).ToList();
            return list;
        }

    }


}
